<?php
	header('Content-Type: text/html;charset=UTF-8');
?>

<?php
include('../../Redirect_modules.php');
	if(clean_param($_REQUEST['modfunc'],PARAM_ALPHAMOD)=='print_all' && $_REQUEST['report'])
	{
		/*	$sql = "select
				(select title from course_subjects where subject_id=(select subject_id from courses where 						course_id=course_periods.course_id)) as subject,
				(select title from courses where course_id=course_periods.course_id) as COURSE_TITLE,
				 short_name, 
				(select title from school_periods where period_id=course_periods.period_id) as period, 
				marking_period_id, 
				(select CONCAT(LAST_NAME,' ',FIRST_NAME,' ',MIDDLE_NAME,' ') from staff where staff_id=course_periods.teacher_id) as teacher, 
				room as location,days,course_period_id,course_id
				from course_periods where school_id='".UserSchool()."' and syear='".UserSyear()."' ".$where." order by subject,COURSE_TITLE";
				
                                

			$ret = DBGet(DBQuery($sql));
                 * 
                 */
                        $sql_subject='SELECT SUBJECT_ID,TITLE FROM  course_subjects WHERE
                                        SCHOOL_ID='.UserSchool().' AND SYEAR= '.UserSyear() ;
                        $sql_subject_ret = DBGet(DBQuery($sql_subject));
                        if(count($sql_subject_ret))

		{
			foreach($sql_subject_ret as $subject)
			{
                        echo "<table width=100%  style=\" font-family:Arial; font-size:12px;\" >";
			echo "<tr><td width=105>".DrawLogo()."</td><td  style=\"font-size:15px; font-weight:bold; padding-top:20px;\">". GetSchool(UserSchool())."<div style=\"font-size:12px;\">All Courses</div></td><td align=right style=\"padding-top:20px;\">". ProperDate(DBDate()) ."<br /></td></tr><tr><td colspan=3 style=\"border-top:1px solid #333;\">&nbsp;</td></tr></table>";
                        echo '<table border="0" width="100%" align="center"><tr><td><font face=verdana size=-1><b>'.$subject['TITLE'].'</b></font></td></tr><tr>';

                        $sql_course='SELECT COURSE_ID,TITLE FROM  courses WHERE
                                        SCHOOL_ID='.UserSchool().' AND SYEAR= '.UserSyear().' AND SUBJECT_ID='.$subject['SUBJECT_ID'] ;

			$sql_course_ret = DBGet(DBQuery($sql_course));
                        foreach($sql_course_ret as $course)
			{
			echo '<table border="0"><tr><td style=padding-left:40px;><font face=verdana size=-1><b>'.$course['TITLE'].'</b></font></td></tr></table>';
                        
                        $sql_course_period='SELECT TITLE FROM  course_periods WHERE
                                        SCHOOL_ID='.UserSchool().' AND SYEAR= '.UserSyear().' AND COURSE_ID='.$course['COURSE_ID'] ;

			$sql_course_period_ret = DBGet(DBQuery($sql_course_period));
                            foreach($sql_course_period_ret as $course_period)
			{
			echo '<table border="0" width="100%"><tr><td style=padding-left:80px;><font face=verdana size=-1><b>'.$course_period['TITLE'].'</b></font></td></tr></table>';
                        }

                        }
			echo '</tr><tr><td colspan="2" valign="top" align="right">';
			echo '</td></tr></table>';
			echo "<div style=\"page-break-before: always;\"></div>";
			}
		}
                    
	/*
          	if(count($ret))

		{
			foreach($ret as $s_id)
			{
			
			echo "<table width=100%  style=\" font-family:Arial; font-size:12px;\" >";
			echo "<tr><td  style=\"font-size:15px; font-weight:bold; padding-top:20px;\">". GetSchool(UserSchool())."<div style=\"font-size:12px;\">Course Catalog</div></td><td align=right style=\"padding-top:20px;\">". ProperDate(DBDate()) ."<br /></td></tr><tr><td colspan=2 style=\"border-top:1px solid #333;\">&nbsp;</td></tr></table>";

			echo '<table border="0" width="97%" align="center"><tr><td><font face=verdana size=-1><b>'.$s_id['SUBJECT'].'</b></font></td></tr>';
			echo '<tr><td align="right"><table border="0" width="97%"><tr><td><font face=verdana size=-1><b>'.$s_id['COURSE_TITLE'].'</b></font></td></tr>';
			echo '<tr><td colspan="2" valign="top" align="right"><table border="0" width="97%"><tr><td>';
			echo '</td></tr></table></td></tr></table></td></tr></table></td></tr>';
			echo '</table></div>';
			echo "<div style=\"page-break-before: always;\"></div>";
			}
		}
                */
	}
	else
	{
		PopTable('header','Print all Courses','width=700');
		DrawHeader('<div align="center">Report Generated</div>');
		echo "<FORM name=exp id=exp action=for_export.php?modname=$_REQUEST[modname]&modfunc=print_all&_openSIS_PDF=true&report=true method=POST target=_blank>";
		echo '<table width=100%><tr><td align="center"><INPUT type=submit class=btn_medium value=\'Print\'></td></tr></table>';
		echo '</form>';
		PopTable('footer');
	}

?>
